// component/search-hd/search-detail/search-tetail.js
const F2 = require('../../../../component/ui/f2-canvas/lib/f2')
const api = require('../../../../wxapi/config.js')
Page({
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {
    return {
      title: '影视行业大数据',
      path: '/pages/index/inedx/index',
    }
  },
  data: {
    busiId: '',
    poster: {
      mc: '-',
      dz: '-',
      xb: '-',
      cs_rq: '-',
      jj: '-',
      url: ''
    },
    haibaoimg: 'https://cdn.xtde.cn/wxapp/xtde/haibao.png',
    roundBtnGroup: [],
    roundBtnactiveIndex: 0,
    worklist: [],
		artistList: [],
    isworksloading: false,
		isArtislistloading: false
  },
  onLoad: function(options) {
    this.setData({
      busiId: options.id
    })
    this.getPoster(options.id)
  },
  // 切换个人简介/个人作品/相关艺人
	onChangeNav(event) {
		if (event.detail.index === 1 && this.data.worklist.length === 0) {
			this.getWorks(this.data.busiId, 0)
		} else if (event.detail.index === 2 && this.data.artistList.length === 0) {
			this.getArtisData(this.data.busiId, 0)
		}
  },
	goActorDetail(e) {
		wx.navigateTo({
			url: '/pages/search/search-detail/actor-detail/actor-detail?id=' + e.currentTarget.dataset.id + '&name=' + e.currentTarget.dataset.name + '&type=' + e.currentTarget.dataset.type
		})
	},
  goDetail(event) {
    if (event.currentTarget.dataset.type === '0') {
      wx.navigateTo({
        url: '/pages/search/search-detail/film-detail/film-detail?id=' + event.currentTarget.dataset.id + '&name=' + event.currentTarget.dataset.name + '&type=2'
      })
    } else {
      wx.navigateTo({
        url: '/pages/search/search-detail/telepaly-detail/telepaly-detail?id=' + event.currentTarget.dataset.id + '&name=' + event.currentTarget.dataset.name + '&type=1'
      })
    }
  },
  onChangeWoeksTag(event) {
    this.setData({
      roundBtnactiveIndex: event.currentTarget.dataset.index
    })
    this.getWorks(this.data.busiId, event.currentTarget.dataset.index)
  },
  // 获取艺人海报信息
  getPoster(id) {
    api.getArtistPosterList({
      busiId: id
    }).then((res) => {
      if (res.data.length !== 0) {
        this.setData({
          poster: res.data
        })
      } else {
        this.setData({
          poster: {}
        })
      }
    })
  },
  // 获取艺人作品列表
  getWorks(id, tag) {
    var telepalyCont = 0
    var filmCont = 0
    this.setData({
      isworksloading: true
    })
    api.getActorList({
      busiId: id,
      tag: tag
    }).then((res) => {
      if (res.data.length != 0) {
        if (tag == 0) {
          for (let i in res.data) {
            for (let j in (res.data)[i]) {
              if ((res.data)[i][j].type == 1) {
                telepalyCont++
              } else {
                filmCont++
              }
            }
          }
          this.setData({
            roundBtnGroup: [{
                name: '全部作品',
                cont: telepalyCont + filmCont
              },
              {
                name: '电视剧',
                cont: telepalyCont
              },
              {
                name: '电影',
                cont: filmCont
              }
            ]
          })
        }

        this.setData({
          worklist: res.data
        })
				// console.log(this.data.worklist)
      } else {
        this.setData({
          worklist: []
        })
      }
      this.setData({
        isworksloading: false
      })
    })
  },
	getArtisData(wid, val) {
		this.setData({
			isArtislistloading: true
		})
		api.getArtistCooperList({ wid: wid, tag: val }).then((res) => {
			if (res.data.length !== 0) {
				this.setData({
					artistList: res.data,
					isArtislistloading: false
				})
			} else {
				this.setData({
					artistList: [],
					isArtislistloading: false
				})
			}
		})
	}
})